package com.woniuxy.authserver.service.impl;

import com.woniuxy.authserver.entity.User;
import com.woniuxy.authserver.mapper.UserMapper;
import com.woniuxy.authserver.service.CustomUserDetailsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;


@Slf4j
@Service
public class CustomUserDetailsServiceImpl implements CustomUserDetailsService {
    @Resource
    private UserMapper userMapper;

    // UserDetails: 用户信息对象，里面封装了用户的信息，例如角色、权限信息
    @Override
    public UserDetails loadUserByUsername(String account) throws UsernameNotFoundException {
        log.debug(account);

        User user = userMapper.findByAccount(account);

        if (user == null){
            throw new UsernameNotFoundException("账号不存在");
        }

        return user;
    }
}
